package com.qf.mrmd.service.impl;

import com.qf.mrmd.entity.Pic;
import com.qf.mrmd.dao.PicDao;
import com.qf.mrmd.result.ResponseCode;
import com.qf.mrmd.result.ResponseData;
import com.qf.mrmd.service.PicService;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Pic)表服务实现类
 *
 * @author makejava
 * @since 2021-07-12 16:16:54
 */
@Service("picService")  //spring接管实现类

public class PicServiceImpl implements PicService {


    @Resource
    private PicDao picDao;


    @Override
    public Pic queryById(Integer pId) {
        Pic pic = new Pic();
        pic.setpId(pId);
        pic.setType("lb");
        pic.setStatus(1);
        return null;
    }

    @Override
    public List<Pic> queryAllByLimit(int offset, int limit) {
        return null;
    }

    @Transactional         //开启事务
    @Override
    public Pic insert(Pic pic) {
        int i = picDao.insert(pic);

        return pic;
    }

    @Override
    public Pic update(Pic pic) {
        return null;
    }

    @Override
    public boolean deleteById(Integer pId) {
        return false;
    }

    @Override
    public ResponseData savePicInfo(Pic pic) {
        pic.setStatus(0);
        int i = picDao.insert(pic);
        if(i>0){
            return new ResponseData(ResponseCode.SUCCESS,pic);
        }
        return new ResponseData(ResponseCode.FAILED,null);
    }

    @Override
    public ResponseData saveData(Pic pic) {
        pic.setStatus(0);
        int i = picDao.insert(pic);
        if(i>0){
            return new ResponseData(ResponseCode.SUCCESS,pic);
        }

        return new ResponseData(ResponseCode.FAILED,null);
    }

    @Override
    public ResponseData queryByType(String type) {
        Pic pic = new Pic();
        pic.setType(type);
        List<Pic> pics = picDao.queryAll(pic);
        return new ResponseData(ResponseCode.SUCCESS,pics);

    }
}
